<template>
  <el-form ref="optForm" :model="form" class="el-dialog__body" label-width="100px">
    <div class="ledgerTitle">基本信息</div>
    <div style="margin: 0 auto; width: 945px;">
      <el-row style="font-size: 15px; line-height: 2.6;">
        {{ form.auditedCompanyName }}:<br/>
        &ensp;&ensp;&ensp;&ensp;根据《中华人民共和国审计法》第四十四条的规定，现将对你单位 {{ form.projectName }} 的审计报告
        送给你们征求意见。请在收到审计报告之日起十日内提出书面意见（写在下面空页内），送交审计处。
      </el-row>
      <el-row>
        <el-col style="display: flex; justify-content: flex-end;">
          {{form.releaseTime}}
        </el-col>
      </el-row>
    </div>
    <div class="ledgerTitle" v-if="form.feedback">被审计单位反馈意见</div>
    <el-form-item label="反馈意见：" v-if="form.feedback">
      <pre class="pre-style">{{ form.feedback }}</pre>
    </el-form-item>
    <div class="ledgerTitle" v-if="form.revisionSuggestions">修改意见</div>
    <el-form-item label="修改意见：" v-if="form.revisionSuggestions">
      <pre class="pre-style">{{ form.revisionSuggestions }}</pre>
    </el-form-item>
    <div class="ledgerTitle">征求意见书</div>
    <div class="inputBox" @click="openWord">
      <div class="inputBox">
        <el-input :readonly="true" v-model="form.projectName"></el-input>
        <ul class="fileBar" v-if="form.wordFile">
          <li @click="openWord('view')"><i class="el-icon-search"></i></li>
          <li @click="downWord"><i class="el-icon-download"></i></li>
        </ul>
      </div>
    </div>
  </el-form>
</template>
<script>

import {getAdvice} from "@/api/adis/report/advice";
import {mapGetters} from "vuex";
import WebDocument from "@/components/form/webDocument.vue";

export default {
  name: 'AuditAdviceView',
  props: {
    id: {
      type: String,
      default: ''
    },
    params: {
      type: Object,
    },
    isAudit: {
      type: Boolean,
      default: false,
    }
  },
  computed:{
    ...mapGetters(["permissions"])
  },
  components: {WebDocument},
  dictTypes: ['audit_type'],
  data() {
    return {
      form: {},
    }
  },
  watch: {
    id: {
      handler(val) {
        if (val) {
          getAdvice(this.id).then((res) => {
            if (res.data.data !== null){
              this.handleAdviceResponse(res.data.data)
              this.$emit('data-loaded', true);
            } else {
              this.$emit('data-loaded', false);
            }
          }).catch(() => {
            this.$emit('data-loaded', false);
          });
        }
      },deep: true, immediate: true
    },
    params: {
      handler(val){
        if (val){
          this.handleAdviceResponse(val)
        }
      },deep: true, immediate: true
    }
  },
  methods: {
    handleAdviceResponse(val) {
      this.form = val;
      this.form.releaseTime = val.updateTime.split(" ")[0]
    },
    downWord() {
      if(!this.form.wordFile) {
        this.$message({
          type: "warning",
          message: "该项尚未上传相关文书!"
        });
        return;
      }
      const a = document.createElement('a');
      let url = this.form.wordFile;
      a.setAttribute('download', '');
      a.setAttribute('href', url);
      a.click();
    },
    openWord() {
      if(!this.form.wordFile) {
        this.$message({
          type: "warning",
          message: "该项尚未上传相关文书!"
        });
        return;
      }
      // this.$router.push({path:'/webOffice', query: {url: this.form.wordFile}})
      const { href } = this.$router.resolve({
        path: '/webOffice',
        query: {
          url: this.form.wordFile,
          type: this.isAudit ? 'edit' : 'view',
        }
      });
      window.open(href, '_blank');
    }
  }
}
</script>
